package com.wc.codeforces.二分.Equalize;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/7/4 9:40
 * @description https://codeforces.com/problemset/problem/1928/B
 */
public class Main {
    /**
     * 思路：
     * 排列相当于1 ~ n各有一个需要加到上面去
     * 首先贪心一点，就是每一个加上去都有效, 那就相当于排序了加上去了
     * 那是不是相当于最多的是排序之后的连续段的长度呢,
     * 那怎么快速判断这连续段的是否满足条件呢, 是不是mx - mn < n就可以了, 然后这个判断是有二分性质的
     * 但是里面有重复的怎么办, 那就事先去重, 完美解决,
     * 理论成立, 开始实践
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 200010;
    static int[] a = new int[N];
    static int n, len;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            n = sc.nextInt();
            for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
            Arrays.sort(a, 1, n + 1);
            // 去重复
            len = 0;
            for (int i = 1; i <= n; i++) {
                if (a[i] != a[i - 1]) a[++len] = a[i];
            }
            int l = 1, r = len;
            while (l < r) {
                int mid = l + r + 1 >> 1;
                if (check(mid)) l = mid;
                else r = mid - 1;
            }
            out.println(r);
        }
        out.flush();
    }

    static boolean check(int mid) {
        for (int l = 1; l + mid - 1 <= len; l++) {
            int r = l + mid - 1;
            if (a[r] - a[l] < n) return true;
        }
        return false;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
